<template>
  <basic-container>
    <div class="avue-crud">
      <el-form :inline="true">
        <el-form-item label="工位名称:" prop="workPositionName">
          <el-input
            v-model="queryParams.workPositionName"
            placeholder="请输入工位名称"
            clearable
            size="small"
            @keyup.enter.native="getList"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
          <el-button
            v-if="permissions.pfoc_workposition_add"
            icon="el-icon-plus"
            type="primary"
            @click="addOrUpdateHandle(false,null,null)">
            添加
          </el-button>
        </el-form-item>
        <el-form-item style="float: right">
          <el-button icon="el-icon-refresh" @click="getList" circle></el-button>
        </el-form-item>
      </el-form>

      <el-table
        v-loading="loading"
        border
         height="75vh"
        :data="menuList"
        row-key="id"
        :tree-props="{children: 'children', hasChildren: 'hasChildrens'}">
        <el-table-column prop="name" label="工位类型" :show-overflow-tooltip="true" align="center" >
        </el-table-column>
        <el-table-column prop="workPositionName" label="工位" :show-overflow-tooltip="true" align="center" ></el-table-column>
        <el-table-column prop="sortOrder" label="工位顺序" align="center"></el-table-column>
        <el-table-column prop="workPositionType" label="类别" :show-overflow-tooltip="true"  align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.workPositionType === '0'" type="danger">工位类型</el-tag>
            <el-tag v-if="scope.row.workPositionType === '1'" type="success">工位</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createBy" label="创建人" align="center" width="100">
          <template slot-scope="scope">
            <div  v-for="(u,index) in userList"   v-if="scope.row.createBy === u.username">
              {{u.name}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center" width="130"></el-table-column>
        <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              v-if="permissions.pfoc_workposition_add && scope.row.workPositionType==='0'"
              size="small"
              type="text"
              icon="el-icon-plus"
              @click="addOrUpdateHandle(false,scope.row.id,'1')">新增
            </el-button>
            <el-button
              v-if="permissions.pfoc_workposition_edit"
              size="small"
              type="text"
              icon="el-icon-edit"
              @click="addOrUpdateHandle(true,scope.row.id)">修改
            </el-button>
            <el-button
              v-if="permissions.pfoc_workposition_del"
              size="small"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <table-form v-if="addOrUpdateVisible" ref="addOrUpdates" @refreshDataList="getList"></table-form>
    </div>

  </basic-container>
</template>

<script>
import { fetchMenuTree,delObj} from '@/api/pfoc/workposition'
import TableForm from './workPosition-form'
import {getAllUser} from "@/api/admin/user";
import { mapGetters } from 'vuex'
export default {
  name: 'workPosition',
  components: {TableForm},
  data() {
    return {
      addOrUpdateVisible: false,
      id:null,
      parameterDialogVisible:false,//修改页面开关
      parameterDialogFull:false,//修改页面弹窗缩放开关（默认放大）
      workPositionName:null,//工位名称
      // 遮罩层
      loading: true,
      // 菜单表格树数据
      menuList: [],
      // 菜单树选项
      menuOptions: [],
      userList:[],//用户集合
      // 查询参数
      queryParams: {
        parentId: undefined,//父ID
        workPositionName: null,//工位名称
      }

    }
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  created() {
    this.getList()
    //获取用户集合
    this.getUserData()
  },
  methods: {
    addOrUpdateHandle(isEdit, id , workPositionType) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdates.init(isEdit, id, workPositionType)
      })
    },
    //获取用户集合
    getUserData(){
      getAllUser().then(response => {
        this.userList = response.data.data
      })
    },
    getList() {
      this.loading = true
      fetchMenuTree(this.queryParams).then(response => {
        this.menuList = response.data.data
        console.log(this.menuList)
        this.loading = false
      })
    },
    handleDelete(row) {
      this.$confirm('是否确认删除名称为"' + row.name + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delObj(row.id)
      }).then(() => {
        this.getList()
        this.$message.success('删除成功')
      })
    },

  }
}
</script>
<style scoped>
/deep/ .el-dialog-right{
  left: 40%;
  position: fixed;
  margin-top: 0!important;
  -webkit-animation: rtl-drawer-in .3s 1ms!important;
  animation: rtl-drawer-in .3s 1ms!important;
}
/deep/ .el-dialog.is-fullscreen{
  width: 100%;
  margin-top: 0;
  margin-bottom: 0;
  height: 100%;
  overflow: auto;
  left: 0!important;
}
/deep/ .el-dialog__header{
  border-bottom: 1px solid rgb(240, 240, 240);
  padding: 20px 20px!important;
}
/deep/ .el-dialog__body{
  height: 100%;
  overflow-y: auto;
}
</style>

